package com.example.fittrack.config;

import com.example.fittrack.R.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    /* 添加校验参数异常处理 */
    @ExceptionHandler(BindException.class)
    public R bindExceptionHandler(BindException e) {
        log.error("出现了异常! {}", e);
        return R.FAILED(R.CODE_FAILED, e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
    }
}